Blog

ColdBox Presents: Groovy Integration

Luis Majano April 15, 2009

Spread the word

Luis Majano

April 15, 2009

Spread the word


Share your thoughts

We are releasing a 1.0 version of our GroovyLoader plugin for ColdBox Applications today.  This plugin can be found in the extra downloads section of the ColdBox Website as part of the projects pack.  So what did we do, well, based on Barney Boisvert's inspiration on CFGroovy, we decided to create a plugin that would leverage ColdBox users with the Groovy Scripting Language.  We took some different approaches to the integration and we still have many things planned for it.  But as of now, these are the features that our GroovyLoader exhibits
  • Drop and Play functionality on ANY ColdBox application running on Railo 3.0 >, Adobe CF 8 >, or Open BD
  • Load a groovy environment (1.6.0) into any ColdBox application without modifying the running CF engine.  It uses our integrated JavaLoader to load all necessary libraries without modifying the CF engine.  It can also, load up ANY library you place in the GroovyLoader's lib directory automatically.  So if you kids start fooling around with packaged groovy libraries or java libraries like Hibernate, Spring, Gorm, etc. You can do so, by just dropping the files in that pre-configured folder.
  • Setup of a directory that will hold groovy classes/scripts, that the GroovyLoader will try to load at runtime. Uses the configureClassPath() method of the plugin and usually called once.
  • Integration with the ColdBox cache to provide resolution of parsed groovy-to-java classes for all parsed groovy source, including custom groovy source compilations
  • Ability to clean the parsed class cache from the ColdBox cache
  • Ability to clean the groovy classloader cache of parsed bits
  • Ability to handle complex groovy/java relationships and hierarchies
  • Easily extend/decorate the plugin to meet your needs or enhance it
  • Create groovy classes: create(clazz)
  • Execute groovy scripts: runScript(scriptName,varCollection)
  • Execute groovy source code: runSource(scriptSource,varCollection)
  • Execute groovy source code using a custom tag import
  • Groovy scripts and source code executions will be binded with the following variables. This means that the groovy scripts that are executed using runScript() and runSource() will have the following variables IMPLICITLY created at runtime. This creates a data bridge between ColdFusion and Groovy.
    • A custom passed structure called varCollection. This can have anything you like.
    • The coldbox request collection: coldbox_rc
    • The following coldfusion variables:
      • cf_pagecontext : The coldfusion pagecontext object
      • cf_application : The coldfusion application scope
      • cf_server : The coldfusion server scope
      • cf_session : The coldfusion session scope (if available)
So how does it work. Well, first of all, the download includes a very simple application that you can replicate and learn from.  As our integration progresses we will be adding more functionality and some extra surprises our very own Sana Ullah has been working on for quite a while now. Step1: Install the custom plugin in your application or as a core plugin, basically drop the GroovyLoader folder in your plugins directory of your app Step 2: Init the plugin on application start, usually the application start handler: Step 3: That's it, you can now use it a la carte to create groovy classes, run scripts, or run on deman source code via the method or the imported tag. You can see some sample handler methods below: var rc = event.getCollection(); rc.oHello = instance.GroovyLoader.create("Hello"); event.setView("home"); var rc = event.getCollection(); instance.GroovyLoader.clearClazzCache(); setNextEvent('groovy'); rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runScript('Test',rc.varCollection); event.setView("runscript"); var rc = event.getCollection(); /* Source */ var source = "varCollection.GroovyArray = [1,2,3,4]"; rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runSource(source,rc.varCollection); event.setView("runSource"); def today = coldbox_rc["today"] def SubjectLine = ["Hello","my","name","is","Luis Majano.","Expressed at",today] //Place in ColdBox event context coldbox_rc["SubjectLine"] = SubjectLine.join("_") I hope you enjoy this plugin and you help make it even better and better.

Add Your Comment

(3)

Apr 16, 2009 16:37:35 UTC

by Manithan

That is really great which is the perfect timing i was just looking for it where i have dynamic bean created and was planing to use with spring. i am really excited to try this one. thanks a lot. you rock!!!

Apr 22, 2009 04:45:05 UTC

by Martin

WOW - thats is what i need - thanks a lot! But the only question for me is: How can i use the hibernate plugin? In the CFGroovy project from Barny there is hibernate integrated. Is there a way to integrate it easy in the Coldbox-Groovy Plugin? My idea is to make the whole DAO-Layer in groovy+hibernate. and call it from CFCs :-)

Apr 22, 2009 11:28:51 UTC

by Luis Majano

HI Martin, We will be adding hibernate support in the next release. However, you are more than welcome to give it a shot. All the hooks are in place to set this up.

Recent Entries

Into the Box 2025 | Plan Your Trip With Us!

Into the Box 2025 | Plan Your Trip With Us!

Are you ready to join us for Into the Box 2025 from April 30th to May 2nd in Washington, D.C.? Let’s make your trip planning as smooth as possible. Here you’ll find Airfare discounts, Hotel Deals and fun things to do to the the best out of your trip to D.C.

Maria Jose Herrera
Maria Jose Herrera
January 30, 2025
BoxLang YAML Support has landed

BoxLang YAML Support has landed

We’re thrilled to introduce the bx-yaml module for BoxLang!

This powerful new module brings seamless YAML parsing and emitting capabilities to BoxLang. You can now effortlessly serialize BoxLang native types—including structs, queries, arrays, classes, and more—into YAML. The same simplicity applies to deserialization, making it easy to work with YAML data in your BoxLang applications.

Luis Majano
Luis Majano
January 28, 2025
TestBox v6.1.0 Release

TestBox v6.1.0 Release

We’re super excited to announce the release of TestBox 6.1.0! This release introduces native support for BoxLang without the need for a compatibility mode, unlocking new possibilities for developers embracing BoxLang’s dynamic capabilities. Alongside this exciting update, we’ve added valuable features, improved functionality, and resolved key issues to ensure a smoother and more robust testing experience. Dive into the details and see how TestBox 6.1.0 makes your testing even more seamless and efficient!

Luis Majano
Luis Majano
January 28, 2025